<?php $dir = stripslashes($_GET['dir']); // lets find the file we are talking about
$real_dir = realpath("$dir"); // returns the proper dir()
include('functions.php');
if($upload != 'true') {
die('<META HTTP-EQUIV="Refresh" CONTENT="0; URL=list.php">');
}
if ($_SESSION["pass"] != check($_SESSION["user"])) {
die('<META HTTP-EQUIV="Refresh" CONTENT="0; URL=login.php">');
}
?>
<title>oPanel V<?php echo $ver; ?></title>
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet"href="style.css">
<?php
// sets the directory that you are uploading to
$upload_dir = $real_dir.DIRECTORY_SEPARATOR;

   //check if the directory exists or not.
   if (!is_dir("$upload_dir")) {
      die ("Error: The directory <b>($upload_dir)</b> doesn't exist");
   }
   //check if the directory is writable.
   if (!is_writeable("$upload_dir")){
      die ("Error: The directory <b>($upload_dir)</b> is NOT writable, Please CHMOD (777)");
   }


//if the form has been submitted, then do the upload process
//infact, if you clicked on (Upload Now!) button.
if (isset($_POST['upload_form'])){

       echo "<h3>Upload results:</h3>";

       //do a loop for uploading files based on ($num_files) number of files.
       for ($i = 1; $i <= 12; $i++) {

           //define variables to hold the values.
           $new_file = $_FILES['file'.$i];
           $file_name = $new_file['name'];
           //to remove spaces from file name we have to replace it with "_".
           $file_name = str_replace(' ', '_', $file_name);
           $file_tmp = $new_file['tmp_name'];
           $file_size = $new_file['size'];

           #-----------------------------------------------------------#
           # this code will check if the files was selected or not.    #
           #-----------------------------------------------------------#

           if (!is_uploaded_file($file_tmp)) {
              //print error message and file number.
              echo "File $i: Not selected.<br>";
           }else{
                             #-----------------------------------------------------------#
                             # this code check if file is Already EXISTS.                #
                             #-----------------------------------------------------------#
                   if(isset($_POST['overwrite']) && $_POST['overwrite'] != "1") {
                             if(file_exists($upload_dir.$file_name)){
                                 echo "$file_name already exists.<br>";
                             }else{

                                   #-----------------------------------------------------------#
                                   # this function will upload the files.  :) ;) cool          #
                                   #-----------------------------------------------------------#
                                   if (move_uploaded_file($file_tmp,$upload_dir.$file_name)) {
                                       echo "File $i: ($file_name) Uploaded.<br>";
                                   }else{
                                        echo "File $i: Faild to upload.<br>";
                                   }#end of (move_uploaded_file).

                             }#end of (file_exists).
                               } else {
                                   #-----------------------------------------------------------#
                                   # this function will upload the files.  :) ;) cool          #
                                   #-----------------------------------------------------------#
                                   if (move_uploaded_file($file_tmp,$upload_dir.$file_name)) {
                                       echo "File $i: ($file_name) Uploaded.<br>";
                                   }else{
                                        echo "File $i: Faild to upload.<br>";
                                   }#end of (move_uploaded_file).
                               }

           }#end of (!is_uploaded_file).

       }#end of (for loop).
       # print back button.
       echo "<a href=\"list.php?dir=$dir\">back to $upload_dir</a>";
////////////////////////////////////////////////////////////////////////////////
//else if the form didn't submitted then show it.
}else{
    echo "Please select files to upload to $real_dir".DIRECTORY_SEPARATOR;
    echo " <form method=\"post\" action=\"$_SERVER[PHP_SELF]?dir=$dir\" enctype=\"multipart/form-data\">";
           // show the file input field based on($num_files).
           for ($i = 1; $i <= 12; $i++) {
               echo "<input type=\"file\" name=\"file". $i ."\">";
               }
echo "<br>Overwrite existing files:
  <input type=\"checkbox\" name=\"overwrite\" value=\"1\">
  <br>
           <input type=\"submit\" name=\"upload_form\" value=\"Upload\">
           </form>";
       echo "<a href=\"list.php?dir=$dir\">back to $real_dir".DIRECTORY_SEPARATOR."</a>";
}
?>
<div style="position: absolute; width: 264px; height: 17px; z-index: 1; bottom: 0px; left:10px" id="credits">
oPanel V<?php echo $ver; ?> by <a href="http://olliespage.net/" target ="_blank">OlliesPage.net</a></div>
<div style="position: absolute; width: 500px; height: 17px; z-index: 1; bottom: 0px; right: 19px; text-align: right" id="BetaTesters">
BETA testers: <?php echo $BETAtesters; ?></div>